package com.ytzl.gotrip.controller;

import com.ytzl.gotrip.model.GotripUser;
import com.ytzl.gotrip.service.GotripUserService;
import com.ytzl.gotrip.utils.common.Dto;
import com.ytzl.gotrip.utils.common.DtoUtil;
import com.ytzl.gotrip.utils.common.EmptyUtils;
import com.ytzl.gotrip.utils.exception.GotripException;
import com.ytzl.gotrip.vo.userinfo.ItripUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api")
@Api(description = "用户模块控制器")
public class GotripUserController {
    @Resource
    private GotripUserService gotripUserService;

    @ApiOperation(value = "根据用户code查询用户信息",notes = "根据用户查询code查询用户信息  \n" +
            "错误码： \n" +
            " 30003:参数不能为空")


    @RequestMapping("/findByUserCode")
    public Dto findByUserCode(@ApiParam(value = "登录账号")@RequestParam("userCode") String userCode) throws Exception {


            GotripUser byUserCode = gotripUserService.findByUserCode(userCode);

            return DtoUtil.returnDataSuccess(byUserCode);
    }
    @RequestMapping("/ckusr")
    public Dto ckusr(@ApiParam(value = "注册账号")@RequestParam("name") String name) throws Exception {


        GotripUser byUserCode = gotripUserService.findByUserCode(name);
        return  EmptyUtils.isEmpty(byUserCode)?DtoUtil.returnDataSuccess("用户名可用"):DtoUtil.returnFail("名字重复","false");

    }

    @ApiOperation(value = "手机号注册")
    @PostMapping("/registerbyphone")
    public Dto registerByPhone(@ApiParam("注册集合") @RequestBody ItripUserVO itripUserVo) throws Exception {
        gotripUserService.registerByPhone(itripUserVo);
        return DtoUtil.returnDataSuccess("注册成功");
    }
    @PutMapping("/validatephone")
    public Dto validatephone(@ApiParam(value = "登陆手机号")@RequestParam String user,@ApiParam(value = "短信验证码")@RequestParam String code) throws Exception {
        gotripUserService.validatePhone(user,code);
        return DtoUtil.returnDataSuccess("激活成功！！");
    }

}
